#Author: Salvatore Gionfriddo
from Agent import Agent
class HumanAgent(Agent):
    def __init__(self):
        self.state = None
        self.available_actions = []
    def Initialize(self, state, aa):
        print self.state
        self.state = state
        self.available_actions = []
        i = 0
        for a in aa:
            if a == 1:
                self.available_actions.append(i)
            i += 1
    def SelectNextAction(self):
        for i in range (0,3):
            s = ""
            for j in range(0,3):
                s += str(self.state[(i*3)+j])+','
            print s
        print "Your moves: ",self.available_actions
        valid = False
        action = -1
        while not valid:
            try:
                inp = input()
                i = int(inp)
                action = i
            except:
                print "Please enter a number."
            else:
                if i in self.available_actions:
                    valid = True
                else:
                    print "That action is not available"
        return action
    def ApplyResult(self, state, reward, aa):
        self.available_actions = []
        i = 0
        for a in aa:
            if a == 1:
                self.available_actions.append(i)
            i += 1
